home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Information / CSMP Digest / volume 1 / csmp-v1-181.txt < prev    next >
Text File  |  1992-12-31  |  46KB  |  1,207 lines

  1. C.S.M.P. Digest             Sat, 10 Oct 92       Volume 1 : Issue 181
  2.  
  3. Today's Topics:
  4.  
  5.     How do I mount a SCSI device?
  6.     Hermes external in C
  7.     Creating background tasks (HELP!).
  8.     How to increase stack size ???
  9.  
  10.  
  11.  
  12. The Comp.Sys.Mac.Programmer Digest is moderated by Michael A. Kelly.
  13.  
  14. The digest is a collection of article threads from the internet newsgroup
  15. comp.sys.mac.programmer.  It is designed for people who read c.s.m.p. semi-
  16. regularly and want an archive of the discussions.  If you don't know what a
  17. newsgroup is, you probably don't have access to it.  Ask your systems
  18. administrator(s) for details.  (This means you can't post questions to the
  19. digest.)
  20.  
  21. Each issue of the digest contains one or more sets of articles (called
  22. threads), with each set corresponding to a 'discussion' of a particular
  23. subject.  The articles are not edited; all articles included in this digest
  24. are in their original posted form (as received by our news server at
  25. cs.uoregon.edu).  Article threads are not added to the digest until the last
  26. article added to the thread is at least one month old (this is to ensure that
  27. the thread is dead before adding it to the digest).  Article threads that
  28. consist of only one message are generally not included in the digest.
  29.  
  30. The entire digest is available for anonymous ftp from ftp.cs.uoregon.edu
  31. [128.223.8.8] in the directory /pub/mac/csmp-digest.  Be sure to read the
  32. file /pub/mac/csmp-digest/README before downloading any files.  The most
  33. recent issues are available from sumex-aim.stanford.edu [36.44.0.6] in the
  34. directory /info-mac/digest/csmp.  If you don't have ftp capability, the sumex
  35. archive has a mail server; send a message with the text '$MACarch help' (no
  36. quotes) to LISTSERV@ricevm1.rice.edu for more information.
  37.  
  38. The digest is also available via email.  Just send a note saying that you
  39. want to be on the digest mailing list to mkelly@cs.uoregon.edu, and you will
  40. automatically receive each new issue as it is created.  Sorry, back issues
  41. are not available through the mailing list.
  42.  
  43. Send administrative mail to mkelly@cs.uoregon.edu.
  44.  
  45.  
  46. -------------------------------------------------------
  47.  
  48. From: triantos@acsu.buffalo.edu (Nick B Triantos)
  49. Subject: How do I mount a SCSI device?
  50. Date: 31 Aug 92 15:22:42 GMT
  51. Organization: The University at Buffalo
  52.  
  53. Hi,
  54.  
  55. Forgive me if this is in the FAQ, but I couldn't find it.  I'd like to write a
  56. program for myself that, when launched, will simply mount all SCSI devices it
  57. finds in the chain.  I've looked in IM for a magic SCSIMount function, or
  58. something reasonably close, and I can't find anything which I can understand.
  59. Please post any suggestions you might have, or pointers to code which may help
  60. me.
  61.  
  62. Thanks much,
  63. - -Nick
  64.  
  65. - --
  66. Nick Triantos    internet: triantos@acsu.buffalo.edu
  67.                  AOL:      Triantos
  68. "Scientists tell us that the fastest animal on earth, with a top speed of
  69. 120 ft/sec, is a cow that has been dropped out of a helicopter." - Dave Barry
  70.  
  71. +++++++++++++++++++++++++++
  72.  
  73. From: zobkiw@world.std.com (Joe Zobkiw)
  74. Date: 31 Aug 92 17:02:01 GMT
  75. Organization: The World Public Access UNIX, Brookline, MA
  76.  
  77. In article <BtuqLx.2xE@acsu.buffalo.edu> triantos@acsu.buffalo.edu (Nick B Triantos) writes:
  78. >Hi,
  79. >
  80. >Forgive me if this is in the FAQ, but I couldn't find it.  I'd like to write a
  81. >program for myself that, when launched, will simply mount all SCSI devices it
  82. >finds in the chain.  I've looked in IM for a magic SCSIMount function, or
  83. >something reasonably close, and I can't find anything which I can understand.
  84. >Please post any suggestions you might have, or pointers to code which may help
  85. >me.
  86. >
  87.  
  88. Look at the low-level File Manager calls such as PBMountVol...I think this
  89. is what you want.
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. - -- 
  103. - -------------------------------------------------------------
  104. joe zobkiw         zobkiw@world.std.com        aol: aflzobkiw
  105.  
  106. +++++++++++++++++++++++++++
  107.  
  108. From: maarten@fwi.uva.nl (Maarten Carels)
  109. Date: 1 Sep 92 09:17:26 GMT
  110. Organization: FWI, University of Amsterdam
  111.  
  112. zobkiw@world.std.com (Joe Zobkiw) writes:
  113. >In article <BtuqLx.2xE@acsu.buffalo.edu> triantos@acsu.buffalo.edu (Nick B Triantos) writes:
  114. >>Hi,
  115. >>Forgive me if this is in the FAQ, but I couldn't find it.  I'd like to write a
  116. >>program for myself that, when launched, will simply mount all SCSI devices it
  117. >>finds in the chain.  I've looked in IM for a magic SCSIMount function, or
  118. >>something reasonably close, and I can't find anything which I can understand.
  119.  
  120. >Look at the low-level File Manager calls such as PBMountVol...I think this
  121. >is what you want.
  122.  
  123. Guess not. There is much more to do for SCSI devices. You have to:
  124. - - determine it's there. Try to read block 0 from the device (you'll need it
  125.   anyway). If you can't read the block, assume no device present.
  126. - - using block 0, locate the driver on the disk, allocate memory in the system
  127.   heap, read the driver, and jsr to it with some parameters in registers.
  128. - - the driver should post a disk inserted event for any partition it wants
  129.   to be mounted. Process all disk inserted events.
  130.  
  131. Documentation for all of this?
  132. Inside Mac volume IV and V (SCSI manager, scsi disk layout)
  133. some technotes
  134. SCSI Development package (APDA, way out of date, but it some things are only
  135. documented in comments in the example driver).
  136.  
  137. Are you sure you want to make such beastie?
  138. SCSI hacking on macintoshes is fun, but it's not easy (I know, I made disk
  139. drivers).
  140.  
  141. - --maarten
  142. - -- 
  143. In real life:    Maarten Carels
  144.         Computer Science Department
  145.         University of Amsterdam
  146. email:        maarten@fwi.uva.nl
  147.  
  148. +++++++++++++++++++++++++++
  149.  
  150. From: bwilliam@iat.holonet.net (Bill Williams)
  151. Date: 7 Sep 92 09:39:41 GMT
  152. Organization: HoloNet (BBS: 510-704-1058)
  153.  
  154. >>mount all SCSI devices it finds in the chain.....
  155.  
  156.  
  157.  
  158. Do not write a mounting program unless you do it correctly. To do
  159.  it correctly is too much work. I'll demonstrate:
  160.  
  161. Steps include
  162.  
  163. 1: Finding all devices on the bus that are FIXED STORAGE, OPTICAL, and CD-ROM
  164. while ignoring things like Voice Navigators and Scanners. Requires 
  165. knowledge of the SCSI Manager.
  166.  
  167. 2: Unmounting all currently existing unmountable volumes supported by the
  168. existing drivers for safety (plus you won't be able to unmount the system
  169. volume or the current app volume)
  170.  
  171. 3: Finding the first VALID HFS SCSI driver form the devices from the DDM
  172. Driver Descriptor Map, in Block0 structure of disk (first block) Plus
  173. reading just the first 512 bytes of the SCSI Block even if its logical 
  174. block size is larger than 512 bytes.
  175.  
  176. Then via block zero you can deduce which of several Partition map entries
  177. in the PARTITION MAP partition is the desired driver. Then you need to
  178. officially validate the checksum found in the partition map entry
  179. describing the driver you are seeking via IM 5 if the partition map name
  180. begins with 'MACI' in upper OR lower case
  181.  
  182. 4: once found you need to load the driver into memory and check its memory
  183. against its checksum for safety. Also you need to load it into a non
  184. relocatable area of the system heap, and GUARANTEE THAT THE SYSTEM HEAP
  185.  CAN AFFORD to accept a further loss of space (if not in System 7 with
  186. expandable system 7 heaps). Size of driver is stored in partition map
  187. entry but be careful not to multiply the logical block size (its units)
  188. by the "ddSize" of the DDM since Apple structures are all internally
  189.  stored using 512 byte logical blocks.
  190.  
  191. 5: once the driver is ready and found, you need to jumpstart the driver as
  192. if it was being called by the normal bootup processes of the Mac after
  193. ILLEGALLY TAKING OVER THE CURRENT SCSI SLOT SPACE in the driver for that
  194. device using Apples official current regular (non "Cousin It") guidlines:
  195. (unit_Table_Ptr = (DCtlHandle *)UTableBase;
  196. unit_Table_Ptr += 32 + device_ID;/* Point at SCSI ID direct slot */)
  197.  
  198.  
  199. void Mount_SCSI_Drive(long scsi_Address, Ptr driver_Start)
  200. {
  201.   asm {
  202.     movem.l    d0-d7/a0-a6,-(sp)
  203.     suba.l     a0,a0
  204.     moveq.l    #0,d7
  205.     move.l     scsi_Address,d5
  206.     bset.l     #31,d5    ;To indicate not being called at boot time
  207.     move.l     driver_Start,a1
  208.     jsr        (a1)
  209.     movem.l    (sp)+,d0-d7/a0-a6
  210.   } /* asm */
  211.   
  212. } /* pascal void Mount_SCSI_Device(INTEGER_32 scsi_Address... */
  213.  
  214.  
  215. 6: The Driver, not you,has the duty of cycling through partition entries
  216. so Thats all there is. Thats it. They will mount.
  217.  
  218.  
  219.  
  220. Problems with ANY technique such as mounting like this include:
  221. Having drivers ORPANED IN MEMORY! This is because no
  222. SCSI drivers currently have to support a "Close" command and WILL BE
  223. ORPAHANED. They may be may be doing evil background tasks, VBL tasks,
  224. or have nasty shutdown manager calls installed. Taking over a SCSI Slot
  225. space is naughty.
  226.  
  227.  
  228. Conclusion: DO NOT WRITE a "SCSI Probe", nor use SCSI Probe. However the
  229. steps just listed in this article are all properly done in the "SCSI
  230. Director* Assistant 1.5.1" CDEV that has various names and was available
  231. from 18 different companies including APS,Club Mac,VCP, etc etc. 
  232.  
  233. PS "SCSI Probe 3.x" violates most rules and does things such as mounting
  234.  OFFLINE devices that are OFFLINE and not Normal Device Queue Entries 
  235. (such as RAM Disks that are closed down with raw memory addresses in the
  236.  entry, MS-DOS volumes, etc.  KaBOOM.
  237.  
  238. BWilliams
  239.  
  240. (If you need to speak to me use EMail since I never usually read
  241. Mac oriented usenet stuff... but I may start)
  242.  
  243. +++++++++++++++++++++++++++
  244.  
  245. From: bwilliam@iat.holonet.net (Bill Williams)
  246. Organization: HoloNet (BBS: 510-704-1058)
  247. Date: Mon, 7 Sep 1992 08:32:26 GMT
  248.  
  249.  
  250. ---------------------------
  251.  
  252. From: Mary.Hicks@p0.f222.n125.z1.FIDONET.ORG (Mary Hicks)
  253. Subject: Hermes external in C
  254. Date: 29 Aug 92 21:45:18 GMT
  255. Organization: FidoNet node 1:125/222.0 - Macademe/Emma, San Francisco CA
  256.  
  257. I would like to make an external for hermes, just as an example, but I 
  258. dont understand how. I read the Hermes Interface file, but I still need 
  259. help. I currently know how to program in C, but I cant make an external.
  260.  
  261.  
  262.  
  263. How would I compile this into an external.\]
  264.  
  265.  
  266.  
  267. main()
  268.  
  269. {
  270.  
  271. printf(" This is an example of a dumb external!");
  272.  
  273. }
  274.  
  275. - --------------------------------------------------
  276.  
  277. Well thats it. I also have the hermes headers fie in 'C', but how do I 
  278. compile the above code into an external? Please give step by step info.
  279.  
  280.  
  281.  
  282. thanks,
  283.  
  284.          Mary Hicks
  285.  
  286.  
  287.  
  288. - --  
  289. Mary Hicks - via FidoNet node 1:125/555
  290.     UUCP: ...!uunet!hoptoad!kumr!fidogate!222.0!Mary.Hicks
  291. INTERNET: Mary.Hicks@p0.f222.n125.z1.FIDONET.ORG
  292.  
  293. +++++++++++++++++++++++++++
  294.  
  295. From: zaphod@bluemoon.rn.com (Peter Bierman)
  296. Organization: Blue Moon BBS ((614) 868-998[024])
  297. Date: Tue, 01 Sep 92 00:07:35 EDT
  298.  
  299. Mary.Hicks@p0.f222.n125.z1.FIDONET.ORG (Mary Hicks) writes:
  300.  
  301. > I would like to make an external for hermes, just as an example, but I 
  302. > dont understand how. I read the Hermes Interface file, but I still need 
  303. > help. I currently know how to program in C, but I cant make an external.
  304.  
  305. Well, first, get the HermHeaders in Pascal. The HEI file has some 
  306. examples, namely the phone external, that pretty much does what you asked.
  307.  
  308. The basic idea is that your external keeps a block in the heap with 
  309. variables. When you get called, you check a variable to see where you were 
  310. in your external, then you do a BIG case statement to get there. When you 
  311. finish one "stage" you update the stage variable to the next part of the 
  312. external to be called, and then go back to Hermes. Hermes should then do 
  313. some stuff, and call you again, and the cycle goes on.
  314.  
  315. It's pretty simple actually, just takes a little getting used to. Partly 
  316. because for a Mac programer, it's wierd to work in modes.
  317.  
  318.  
  319. - ---
  320. The opinions I express are rarely my own, because my own are far too
  321. outragous to post here.
  322.  
  323. IntNet:zaphod@bluemoon.rn.com    FutureNet: #33@#10
  324. The Metropolis (614)-846-1911
  325. - ---
  326.  
  327. +++++++++++++++++++++++++++
  328.  
  329. From: Glen.Stewart@f175.n2240.z1.ieee.org (Glen Stewart)
  330. Date: 31 Aug 92 14:21:01 GMT
  331. Organization: FidoNet node 1:2240/175 - The Associati, Grand Blanc MI
  332.  
  333. Mary -
  334.  
  335. You're pretty ambitious.  First I read you're looking for Basic source, now C
  336. tips for Hermes...
  337.  
  338. I'm just completing a Think C project which is a very functional Hermes
  339. external.  It's almost fully commented, and the program flow is pretty
  340. understandable.  I'm no pro, but I've picked up that the standard printing
  341. command is not acceptable to Hermes - it wants control of everything like
  342. that.  So there are some special functions you can call that will take care of 
  343. this for you.
  344.  
  345. I'm struggling to fix a problem from the modification I made to the original
  346. program, by Robert Duran Jr.  Once it is fixed (I'll be working on it this
  347. afternoon, I hope), I'll put it online on my BBS and on the Hermes support
  348. BBS.
  349.  
  350. The more basic functions are really easy to implement (simple textual
  351. interaction), but anything calling the idle loop (hooks into the main
  352. interface) are tricky and poorly documented.  I'm also trying to update the
  353. HermesHeader.h to Hermes 2.0 status.  This update is also nearly complete -
  354. trying to get a little help from Robert on this one.
  355.  
  356. Bye for now.
  357.  
  358.  
  359. - --  
  360. =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  361.  Glen Stewart - Internet: Glen.Stewart@f175.n2240.z1.ieee.org
  362.  
  363. ---------------------------
  364.  
  365. From: baer@qiclab.scn.rain.com (Ken Baer)
  366. Subject: Creating background tasks (HELP!).
  367. Date: 13 Aug 92 17:00:29 GMT
  368. Organization: SCN Research/Qic Laboratories of Tigard, Oregon.
  369.  
  370. OK, first of all, I do realize that the Mac OS does not yet support real
  371. Multitasking (nor does MS Windows). But, I keep hearing about certain
  372. applications or inits that allow programs to run in the background (like
  373. the one that allows Think C to compile in the background).  What I want
  374. to do is allow our 3D rendering software to render in the background to
  375. the user can use the modeller etc. while rendering.  Could someone either
  376. post, or point me to some documented code to set this up?  What are the
  377. limits and conditions to this?  We are already doing this under Windows,
  378. so I imagine a similar process should be possible on the Mac.
  379.  
  380. Any and all related information will be greatly appreciated.
  381.  
  382.     -Ken Baer.
  383.     baer@qiclab.scn.rain.com
  384. - -- 
  385.     //    -Ken Baer.  Programmer/Animator, Hash Enterprises
  386.   \X/     Usenet: baer@qiclab.UUCP  /  Office: (206)573-9427
  387.           "Hey, I think a glacier just passed us!" - Andy from Joyride
  388.  
  389. +++++++++++++++++++++++++++
  390.  
  391. From: kent@sunfs3.Camex.COM (Kent Borg)
  392. Date: 14 Aug 92 00:05:35 GMT
  393. Organization: Camex Inc., Boston MA
  394.  
  395. In article <1992Aug13.170029.3055@qiclab.scn.rain.com> baer@qiclab.scn.rain.com (Ken Baer) writes:
  396. >OK, first of all, I do realize that the Mac OS does not yet support real
  397. >Multitasking (nor does MS Windows). 
  398.  
  399. Careful, thousands of people are cringing right now over the flame war
  400. you might have just touched off.  (Some people are so irresponsible.)
  401.  
  402. >But, I keep hearing about certain applications or inits that allow
  403. >programs to run in the background (like the one that allows Think C
  404. >to compile in the background).
  405.  
  406. It is pretty easy for an application to do.  In fact, it is so easy
  407. that INITs have been known to convince certain applications to do it.
  408. (To be honest, I am pretty sure Think C has always allowed some
  409. background processing, it just kept the user tied up while this went
  410. on.)
  411.  
  412. >What I want to do is allow our 3D rendering software to render in the
  413. >background to the user can use the modeller etc. while rendering.
  414. >Could someone either post, or point me to some documented code to set
  415. >this up?
  416.  
  417. Look in Inside Macintosh Volume VI or the new "Processes" volume of
  418. Inside Macintosh for details, but in general, there are two things to
  419. do:
  420.  
  421. 1) When your code gets CPU time (you will know this because it is
  422. executing) do your thing.
  423.  
  424. 2) When the user decides to say something to your running code--for
  425. example canceling the rendering he mistakenly started--notice the
  426. "Stop" menu choice, or "Cancel" button, or command-period keystroke,
  427. and act on it (by stopping in this case).  
  428.  
  429. Because this is a user-oriented machine which is valuable precisely
  430. for its user interface, be very responsive about noticing that the
  431. user is talking to you.  Don't make the user pound on the keyboard.
  432. To notice that the user is talking, call GetNextEvent(), and act on
  433. anything you hear.  (Or call WaitNextEvent() if you are just sitting
  434. around waiting for something to happen.)
  435.  
  436. Oh, and don't do anyThink stupid like putting up a traditional modal dialog
  437. box.  It will prevent the user from switching to another layer.  Use a
  438. regular window or a newer movable modal dialog instead.
  439.  
  440. Simple.  You are done.  You have written a program which is responsive
  441. to the user and it is happily multitasking.
  442.  
  443. Okay, this does mean that inside your tight loops you need to notice
  444. the passage of time and occasionally check for user input.  (Do this
  445. several times a second--and possibly be clever and calibrate this at
  446. runtime based on how fast my Mac can run your loop.)  But what do you
  447. expect of an 8-plus-year-old architecture which started out in 128K of
  448. unprotected RAM??  Don't get greedy.
  449.  
  450. The secret: Everytime you call GetNextEvent() or WaitNextEvent() the
  451. system potentially offers execute time to other applications.
  452. Everytime the other applications call one of those routines you
  453. potentially get execute time.  Coopertive multitasking does require
  454. cooperation but it makes for a very user-responsive system when folks
  455. do cooperate.  It is what Modern True Real Time Multitasking Operating
  456. Systems very often do--honest.
  457.  
  458.  
  459. Make Sense?  If not, say so and there will be lots of helpful advice
  460. coming your way--but PLEASE avoid fighting words like "Real
  461. Multitasking" in future postings.
  462.  
  463.  
  464. - --
  465. Kent Borg                                   kent@camex.com or kentborg@aol.com
  466.                                             H:(617) 776-6899  W:(617) 426-3577
  467. As always, things look better when some costs are left out.
  468.                               -Economist 3-28-92 p. 94
  469.  
  470. +++++++++++++++++++++++++++
  471.  
  472. From: mcmath@csb1.nlm.nih.gov (Chuck McMath)
  473. Date: 14 Aug 92 12:32:58 GMT
  474. Organization: MSD
  475.  
  476. In article <1992Aug13.170029.3055@qiclab.scn.rain.com>,
  477. baer@qiclab.scn.rain.com (Ken Baer) wrote:
  478. > OK, first of all, I do realize that the Mac OS does not yet support real
  479. > Multitasking (nor does MS Windows). But, I keep hearing about certain
  480. > applications or inits that allow programs to run in the background (like
  481. > the one that allows Think C to compile in the background).  What I want
  482. > to do is allow our 3D rendering software to render in the background to
  483. > the user can use the modeller etc. while rendering.  Could someone either
  484. > post, or point me to some documented code to set this up?  What are the
  485. > limits and conditions to this?  We are already doing this under Windows,
  486. > so I imagine a similar process should be possible on the Mac.
  487. > Any and all related information will be greatly appreciated.
  488.      
  489.         Well, what you're really seeing is applications that can do tasks in
  490. the background.  When the front application doesn't have pending events and
  491. it calls WaitNextEvent background applications get time - that is, if the
  492. frontmost application is well-behaved (please, gurus, correct me if I
  493. misspeak!)
  494.  
  495. What you want to to is bone up (i.e., read Inside Mac) on the Event Manager
  496. (maybe?) and see how applications that are not in the foreground get time. 
  497. Then you need to structure your rendering task so it can be done in small
  498. chunks, because it would not be polite for a background task to grab the
  499. computer and not let go (cf PrintMonitor!).  Once you set up your renderer
  500. this way, it needs to be on the lookout for those events that apps get when
  501. they're in the background, and do some rendering then.  It's easy to talk
  502. about, but, I believe, difficult to achieve in practice!
  503.  
  504.  
  505. chuck
  506.  
  507. |- chuck mcmath - mcmath@csb1.nlm.nih.gov - MSD, Inc. ------------|
  508. |- National Library of Medicine - National Institutes of Health --|
  509. |- Bethesda, MD 20894 -  !aixelsyd evah uoy siht daer nac uoy fI -|
  510. |- "Hey batter, hey batter, hey batter, swing" - Anon. -----------|
  511.  
  512. +++++++++++++++++++++++++++
  513.  
  514. From: jstevens@crick.ssctr.bcm.tmc.edu (Jason Philip Stevens)
  515. Date: 14 Aug 1992 15:21:17 GMT
  516. Organization: Baylor College of Medicine, Houston, Tx
  517.  
  518.  
  519. In article <1992Aug13.200535.18236@sunfs3.Camex.COM>, kent@sunfs3.Camex.COM (Kent Borg) writes:
  520. |> In article <1992Aug13.170029.3055@qiclab.scn.rain.com> baer@qiclab.scn.rain.com (Ken Baer) writes:
  521.  
  522. |> >What I want to do is allow our 3D rendering software to render in the
  523. |> >background to the user can use the modeller etc. while rendering.
  524. |> >Could someone either post, or point me to some documented code to set
  525. |> >this up?
  526. |> 
  527. |> Look in Inside Macintosh Volume VI or the new "Processes" volume of
  528. |> Inside Macintosh for details, but in general, there are two things to
  529. |> do:
  530. |> 
  531. |> 1) When your code gets CPU time (you will know this because it is
  532. |> executing) do your thing.
  533. |> 
  534. |> 2) When the user decides to say something to your running code--for
  535. |> example canceling the rendering he mistakenly started--notice the
  536. |> "Stop" menu choice, or "Cancel" button, or command-period keystroke,
  537. |> and act on it (by stopping in this case).  
  538.  
  539. Another option that may be more in line with what you really want to do
  540. is use threads.  The new Threads package from apple allows programs to
  541. have multiple threads of execution.  In your case, a single program (not
  542. seperate processes, as described above) could well shunt off all of the 
  543. compute intensive rendering into a new thread, that would chug along while
  544. the user was free to interact with the rest of the program (which resides
  545. in its own thread).
  546.  
  547. - -jps
  548.  
  549. - -- 
  550. Jason Stevens            Internet:  jstevens@bcm.tmc.edu
  551. Network User Services        Voice:  (713) 798-7370
  552. Baylor College of Medicine    Opinions expressed are mine alone.
  553.  
  554.  
  555. +++++++++++++++++++++++++++
  556.  
  557. From: scott@mcl.ucsb.edu (Scott Bronson)
  558. Date: 24 Aug 92 00:50:37 GMT
  559.  
  560. In <1992Aug13.200535.18236@sunfs3.Camex.COM> kent@sunfs3.Camex.COM (Kent Borg) writes:
  561.  
  562. >In article <1992Aug13.170029.3055@qiclab.scn.rain.com> baer@qiclab.scn.rain.com (Ken Baer) writes:
  563.  
  564. >>What I want to do is allow our 3D rendering software to render in the
  565. >>background to the user can use the modeller etc. while rendering.
  566. >>Could someone either post, or point me to some documented code to set
  567. >>this up?
  568.  
  569. >1) When your code gets CPU time (you will know this because it is
  570. >executing) do your thing.
  571.  
  572. >2) When the user decides to say something to your running code--for
  573. >example canceling the rendering he mistakenly started--notice the
  574. >"Stop" menu choice, or "Cancel" button, or command-period keystroke,
  575. >and act on it (by stopping in this case).  
  576.  
  577. 3) Set the "accept background null events" in your size resource or you'll
  578. wait a really long time for your code to finish if you switch it to the
  579. background...  I forget to do this way too often.
  580.  
  581. >Because this is a user-oriented machine which is valuable precisely
  582. >for its user interface, be very responsive about noticing that the
  583. >user is talking to you.  Don't make the user pound on the keyboard.
  584.  
  585. Er, technically speaking the user cannot interact with your program
  586. while it is in the background.  He/she/it must switch it to the
  587. foreground to cancel the rendering.  I assume your renderer already
  588. allows cancel, so no changes here.  I believe the only two events you
  589. get while you are backgrounding are nullEvt and updateEvt and an
  590. OS activate event when you get switched back forward.  (I think...)
  591.  
  592. Pass very small values to the sleepTime parameter in WaitNextEvent
  593. (don't use GetNextEvent unless you HAVE to), and when you get time,
  594. take a tick or two and get a few more calculations again.  Then call
  595. WaitNextEvent so that other processes can get their fair time.  You
  596. can use the following loop so that you can get the processor for a
  597. fair amount of time:
  598.  
  599. // Uncompiled C code from memory below -- use at own
  600. // risk, but you get the idea.
  601. long l; EventRecord e;
  602. while( task not done ) {
  603.     if( WaitNextEvent( everyEvent, &e, 0L, nil ) ) {
  604.     HandleUpdateOrOSEvent();
  605.     } else {
  606.         l = Ticks + 2;
  607.         do {
  608.         SmallIncrementalPartOfYourTask()
  609.     } while( Ticks < l );
  610.     }
  611. }
  612.  
  613. Note that if you want to be future compatible, use TickCount() instead
  614. of the low memory global Ticks.  I use TickCount() because I figure that
  615. if Ticks ever fails, it will be trivial to re-compile using TickCount().
  616. However, none of the apps I've developed have been commercial (so far)
  617. so I haven't had to worry about expensive upgrades.
  618.  
  619. This is how I've been doing it.  If anyone has any suggestions, please
  620. do tell.
  621.  
  622.     - Scott
  623.  
  624. +++++++++++++++++++++++++++
  625.  
  626. From: kent@sunfs3.Camex.COM (Kent Borg)
  627. Date: 24 Aug 92 17:34:40 GMT
  628. Organization: Camex Inc., Boston MA
  629.  
  630. In article <scott.714617437@mcl> scott@mcl.ucsb.edu (Scott Bronson) writes:
  631. >(don't use GetNextEvent unless you HAVE to)
  632.  
  633. Quite right.  My posting was wrong.  I though that WaitNextEvent()
  634. reduced to the same thing as GetNextEvent() when the wait was zero and
  635. the rgn empty.  Wrong.  WaitNextEvent() also calls SystemTask() for
  636. you--and possibly other differences I am still forgetting.  I knew
  637. this and forgot it and got burned by it just last week.
  638.  
  639. Bottom line: Only use GetNextEvent() when WaitNextEvent() doesn't
  640. exist (on old systems, for example).
  641.  
  642. - --
  643. Kent Borg                                   kent@camex.com or kentborg@aol.com
  644.                                             H:(617) 776-6899  W:(617) 426-3577
  645. As always, things look better when some costs are left out.
  646.                               -Economist 3-28-92 p. 94
  647.  
  648. +++++++++++++++++++++++++++
  649.  
  650. From: joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91)
  651. Date: 24 Aug 92 23:49:02 GMT
  652. Organization: NASA/ARC Information Sciences Division
  653.  
  654. In article <1992Aug24.133440.1050@sunfs3.Camex.COM> kent@sunfs3.Camex.COM (Kent Borg) writes:
  655. >In article <scott.714617437@mcl> scott@mcl.ucsb.edu (Scott Bronson) writes:
  656. >>(don't use GetNextEvent unless you HAVE to)
  657. >
  658. >Quite right.  My posting was wrong.  I though that WaitNextEvent()
  659. >reduced to the same thing as GetNextEvent() when the wait was zero and
  660. >the rgn empty.  Wrong.  WaitNextEvent() also calls SystemTask() for
  661.                           ^^^^^^^^^^^^^^^^^^
  662.  
  663. No.  WaitNextEvent() does NOT call systemTask() -- it has it's own
  664. way of dealing with this type of action for you.  But it does not,
  665. to the best of my knowledge, call SystemTask(), which should not be used 
  666. (does nothing?) under systems with WaitNextEvent().
  667.  
  668. >you--and possibly other differences I am still forgetting.  I knew
  669. >this and forgot it and got burned by it just last week.
  670.  
  671. Not trying to flame.
  672.  
  673. >
  674. >Bottom line: Only use GetNextEvent() when WaitNextEvent() doesn't
  675. >exist (on old systems, for example).
  676.  
  677. YES.
  678.  
  679. >
  680. >--
  681. >Kent Borg                                   kent@camex.com or kentborg@aol.com
  682. >                                            H:(617) 776-6899  W:(617) 426-3577
  683. >As always, things look better when some costs are left out.
  684. >                              -Economist 3-28-92 p. 94
  685.  
  686.  
  687. - -- 
  688. - ----------------------------------
  689. #include <std/disclaimer.h>     Josh Rabinowitz, Mac TCL programmer
  690. joshr@kronos.arc.nasa.gov
  691. "Send a salami to your boy in the army" - Katz's delicatessen, NYC
  692.  
  693. +++++++++++++++++++++++++++
  694.  
  695. From: urlichs@smurf.sub.org (Matthias Urlichs)
  696. Date: 8 Sep 92 15:17:51 GMT
  697. Organization: University of Karlsruhe, FRG
  698.  
  699. In comp.sys.mac.programmer, article <1992Aug24.234902.26204@kronos.arc.nasa.gov>,
  700.   joshr@kronos.arc.nasa.gov (Joshua Rabinowitz-Summer-91) writes:
  701. > In article <1992Aug24.133440.1050@sunfs3.Camex.COM> kent@sunfs3.Camex.COM (Kent Borg) writes:
  702. > >In article <scott.714617437@mcl> scott@mcl.ucsb.edu (Scott Bronson) writes:
  703. > >>(don't use GetNextEvent unless you HAVE to)
  704. > >
  705. > >Quite right.  My posting was wrong.  I though that WaitNextEvent()
  706. > >reduced to the same thing as GetNextEvent() when the wait was zero and
  707. > >the rgn empty.  Wrong.  WaitNextEvent() also calls SystemTask() for
  708. >                           ^^^^^^^^^^^^^^^^^^
  709. > No.  WaitNextEvent() does NOT call systemTask() -- it has its own
  710. > way of dealing with this type of action for you.  But it does not,
  711. > to the best of my knowledge, call SystemTask(), which should not be used 
  712. > (does nothing?) under systems with WaitNextEvent().
  713.  
  714. WaitNextEvent calls GetNextEvent when the wait is zero and the region empty.
  715. GetNextEvent calls SystemTask internally.
  716. (This is under System 7.0.1. Set a BReak on WaitNextEvent, Go, set a BReak
  717.  on SystemTask, Go, StackCrawl, examine code at calling points.
  718.  Clear breakpoints, Go.  All this is Macsbug; your debugger may vary. :-)
  719. All three routines are reimplemented by System 7.
  720.  
  721. Given this, calling SystemTask is superfluous but definitely harmless.
  722.  
  723. - -- 
  724. "For that matter, compare your pocket computer with the massive jobs of
  725. a thousand years ago.  Why not, then, the last step of doing away with
  726. computers altogether?"
  727.         -- Jehan Shuman
  728. - -- 
  729. Matthias Urlichs  --  urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de   /(o\
  730. Humboldtstrasse 7 -- 7500 Karlsruhe 1 -- Germany  --  +49-721-9612521     \o)/
  731.  
  732. ---------------------------
  733.  
  734. From: tschneid@uwovax.uwo.ca
  735. Subject: How to increase stack size ???
  736. Organization: University of Western Ont, London
  737. Date: Tue, 1 Sep 1992 18:56:11 GMT
  738.  
  739.  
  740. I am working on a port of Gunplot 3.2 to the Mac. So far I have most
  741. of the basics working (only a few bugs left) ... however, I keep
  742. running out of stack space. I did some reading and found out that the
  743. Mac only provides 8k of stack space and that it can be changed by doing
  744. something like (in VERY rough C pseudo-code)
  745.  
  746.         THz newapplimit;
  747.  
  748.         newapplimit = 300*1024;    /* give app 300k */
  749.         SetApplLimit(ApplLimit()+newapplimit);
  750.         MaxApplLimit();
  751.  
  752. Unfortunately, this does not work ...
  753.  
  754. Can anyone enlighten me? I would like to set up a fixed stack size of
  755. 32k (i.e. not dependent on the memory allotted by the user in the 
  756. applications info box). I am using Think C 5.02.
  757.  
  758. Thanks,
  759. Todd Schneider
  760.  
  761. +++++++++++++++++++++++++++
  762.  
  763. From: damurphy@wc.novell.com (Duane A Murphy)
  764. Date: 2 Sep 92 15:48:22 GMT
  765. Organization: Novell, Inc. - Walnut Creek
  766.  
  767. In article <1992Sep1.145611.1@uwovax.uwo.ca> tschneid@uwovax.uwo.ca writes:
  768. >
  769. >I am working on a port of Gunplot 3.2 to the Mac. So far I have most
  770. >of the basics working (only a few bugs left) ... however, I keep
  771. >running out of stack space. I did some reading and found out that the
  772. >Mac only provides 8k of stack space and that it can be changed by doing
  773. >something like (in VERY rough C pseudo-code)
  774. >
  775. >        THz newapplimit;
  776. >
  777. >        newapplimit = 300*1024;    /* give app 300k */
  778. >        SetApplLimit(ApplLimit()+newapplimit);
  779. >        MaxApplLimit();
  780. >
  781. >Unfortunately, this does not work ...
  782. >
  783. >Can anyone enlighten me? I would like to set up a fixed stack size of
  784. >32k (i.e. not dependent on the memory allotted by the user in the 
  785. >applications info box). I am using Think C 5.02.
  786. >
  787. >Thanks,
  788. >Todd Schneider
  789.  
  790. I also ran into a stack limitation problem.  Actually the stack is handled 
  791. differently on different machines.  It is not consistent.  "Small" machines
  792. have an 8K stack.  "Large" machines have a 24K stack.  There is a low memory
  793. global "DefltStack" that determines the stack size at startup.  Dont mess 
  794. with this, it affects everyone.
  795.  
  796. After a few days of trying to figure out how the stack space is managed; 
  797. that is what pointers in the heap kept track of the stack to detect a
  798. stack heap collision, we came up with the following very simple solution.
  799.  
  800. #define STACK_MIN 0x8000L
  801. pascal Ptr StackPtr(void) = {0x2e8f};    /* MOVE A7, (A7) */
  802.  
  803. int main(void)
  804. {
  805.     SetApplLimit(StackPtr() - STACK_MIN);
  806. ...
  807.  
  808. The StackPtr() function came from the net (thanks to whomever suggested
  809. this).  The stack has no direct pointers to set its limits.  It is actuall
  810. controlled by heap limit pointers, namely ApplLimit.  This moves ApplLimit
  811. the where the current stack is at down the size of the stack that you
  812. want.
  813.  
  814. Hope this helps,
  815. ...Duane Murphy
  816. Novell, Walnut Creek
  817.  
  818. +++++++++++++++++++++++++++
  819.  
  820. From: grobbins@Apple.COM (Grobbins)
  821. Date: 2 Sep 92 18:55:00 GMT
  822. Organization: Apple Computer Inc., Cupertino, CA
  823.  
  824. In article <1992Sep2.154822.12924@novell.com> damurphy@wc.novell.com (Duane A Murphy) writes:
  825. >In article <1992Sep1.145611.1@uwovax.uwo.ca> tschneid@uwovax.uwo.ca writes:
  826. >>...I keep running out of stack space.
  827. >
  828. >I also ran into a stack limitation problem.  Actually the stack is handled 
  829. >differently on different machines.  It is not consistent.  "Small" machines
  830. >have an 8K stack.  "Large" machines have a 24K stack.  There is a low memory
  831. >global "DefltStack" that determines the stack size at startup.  Dont mess 
  832. >with this, it affects everyone.
  833.  
  834. Color QuickDraw machines do have a 24K default stack.  Be aware that
  835. the Process Manager always increases the partition size by (default
  836. stack - 8K) when launching applications, so the extra 16K stack space
  837. on Color QuickDraw machines does not reduce the heap size under what
  838. would be available on a 68000 machine (but the app's partition is
  839. 16K larger than the partition size set by the programmer.)
  840.  
  841. >pascal Ptr StackPtr(void) = {0x2e8f};    /* MOVE A7, (A7) */
  842. >...
  843. >    SetApplLimit(StackPtr() - STACK_MIN);
  844.  
  845. This is a bit more 680x0 dependent than source code should be these
  846. days.  Here's a function which uses documented calls to increase the
  847. stack size.
  848.  
  849.   // Increase the space allocated for the application stack
  850.   //
  851.   // Warning: SetApplLimit always sets the stack to at least as large as the 
  852.   //    default stack for the machine (8K on machines with original QuickDraw,  
  853.   //    24K on machines with Color QuickDraw) so the application partition 
  854.   //    must be large enough to accomodate an appropriate stack and heap
  855.  
  856.   OSErr IncreaseApplicationStack(Size incrementSize)
  857.   {
  858.     OSErr retCode;
  859.   
  860.     // increase the stack size by lowering the heap limit
  861.     SetApplLimit((Ptr) ((unsigned long) GetApplLimit() - incrementSize));
  862.     retCode = MemError();
  863.     if (retCode == noErr) MaxApplZone();
  864.   
  865.     return retCode;
  866.   }
  867.  
  868. Do heed the warning given in the comment.  All stack allocation beyond
  869. the default must be compensated for by increasing the partition size in
  870. the SIZE -1 resource.  
  871.  
  872. This is particularly an issue for faceless background apps, which have
  873. a default stack size of only 2K.  SetApplLimit will grow an FBA's stack
  874. to at least 24K on Color QuickDraw machines, so the partition size
  875. should be larger than that.
  876.  
  877.  
  878. Grobbins               grobbins@apple.com
  879.  
  880. Usual disclaimers apply.
  881.  
  882. +++++++++++++++++++++++++++
  883.  
  884. From: ksand@apple.com (Kent Sandvik)
  885. Date: 2 Sep 92 00:31:07 GMT
  886. Organization: Apple
  887.  
  888. In article <1992Sep1.145611.1@uwovax.uwo.ca>, tschneid@uwovax.uwo.ca wrote:
  889. > I am working on a port of Gunplot 3.2 to the Mac. So far I have most
  890. > of the basics working (only a few bugs left) ... however, I keep
  891. > running out of stack space. I did some reading and found out that the
  892. > Mac only provides 8k of stack space and that it can be changed by doing
  893. > something like (in VERY rough C pseudo-code)
  894.  
  895. MacII ROMs: 24k
  896. Old Macs (Plus, SEs): 8k
  897. Color QuickDraw systems: 24k
  898. MacApp applications (24k by default).
  899.  
  900. >         THz newapplimit;
  901. >         newapplimit = 300*1024;    /* give app 300k */
  902. >         SetApplLimit(ApplLimit()+newapplimit);
  903. >         MaxApplLimit();
  904. > Unfortunately, this does not work ...
  905.  
  906. In what way, collision of stack and heap (more memory required then)?
  907. Other problems?
  908.  
  909. Kent Sandvik/DTS
  910.  
  911. +++++++++++++++++++++++++++
  912.  
  913. From: buckeye@spf.trw.com (John Wallace)
  914. Date: 2 Sep 92 20:23:29 GMT
  915. Organization: TRW Sensor Data Processing Center, Redondo Beach, CA
  916.  
  917. In article <1992Sep2.154822.12924@novell.com> damurphy@wc.novell.com (Duane A Murphy) writes:
  918. >In article <1992Sep1.145611.1@uwovax.uwo.ca> tschneid@uwovax.uwo.ca writes:
  919. >>
  920. >>I keep running out of stack space. 
  921. >>Todd Schneider
  922. >
  923. >I also ran into a stack limitation problem.  Actually the stack is handled 
  924. >differently on different machines.  It is not consistent.  "Small" machines
  925. >have an 8K stack.  "Large" machines have a 24K stack.  
  926. >
  927. >#define STACK_MIN 0x8000L
  928. >pascal Ptr StackPtr(void) = {0x2e8f};    /* MOVE A7, (A7) */
  929. >
  930. >int main(void)
  931. >{
  932. >    SetApplLimit(StackPtr() - STACK_MIN);
  933. >...
  934. >
  935. >
  936. >Hope this helps,
  937. >...Duane Murphy
  938. >Novell, Walnut Creek
  939. >
  940.  
  941. You may want to change this to:
  942.  
  943. if (StackSpace() < STACK_MIN)
  944.     SetApplLimit(StackPtr() - (STACK_MIN - StackSpace()))
  945.  
  946. This will make sure that you don't waste too much memory on "Large"
  947. machines.  (StackSpace is a standard Toolbox trap.)  Also, some 
  948. development envrionments automatically call SetApplLimit as part of 
  949. the normal application startup.  For example, THINK Pascal calls 
  950. SetApplLimit to allocate the amount of stack space you specified under 
  951. your Run Options.  Check your development environment documentation to 
  952. see if it provides this kind of support.
  953.  
  954. Cheers!
  955. John
  956. - ---------------------------------------------------------------------
  957. John Wallace                     buckeye@spf.trw.com
  958.  
  959. +++++++++++++++++++++++++++
  960.  
  961. From: marshall@sdd.hp.com (Marshall Clow)
  962. Date: 2 Sep 92 21:40:32 GMT
  963. Organization: Hewlett Packard San Diego Printer Division
  964.  
  965. In article <71922@apple.Apple.COM>, grobbins@Apple.COM (Grobbins) wrote:
  966. > [ lots of good advice deleted ]
  967. > This is particularly an issue for faceless background apps, which have
  968. > a default stack size of only 2K.  SetApplLimit will grow an FBA's stack
  969. > to at least 24K on Color QuickDraw machines, so the partition size
  970. > should be larger than that.
  971.  
  972. In writing a FBA we tracked down several cases where inits (oops,
  973. extensions) would patch a trap, and then when the trap was called, would
  974. casually throw a few Str255s on the stack, or maybe a 1K buffer.
  975.  
  976. Needless to say, when an OS call used over 1K of stack space and you only
  977. have a 2K stack, you are headed for problems.
  978.  
  979.  
  980. Marshall Clow
  981. San Diego Printer Division      Hewlett Packard
  982. Internet: marshall@sdd.hp.com   AppleLink: HP.Marshall    AOL: MClow
  983.  
  984. +++++++++++++++++++++++++++
  985.  
  986. From: damurphy@wc.novell.com (Duane A Murphy)
  987. Date: 3 Sep 92 18:08:37 GMT
  988. Organization: Novell, Inc. - Walnut Creek
  989.  
  990. In article <71922@apple.Apple.COM> grobbins@Apple.COM (Grobbins) writes:
  991. >
  992. >  // Increase the space allocated for the application stack
  993. >  //
  994. >  // Warning: SetApplLimit always sets the stack to at least as large as the 
  995. >  //    default stack for the machine (8K on machines with original QuickDraw,  
  996. >  //    24K on machines with Color QuickDraw) so the application partition 
  997. >  //    must be large enough to accomodate an appropriate stack and heap
  998. >
  999. >  OSErr IncreaseApplicationStack(Size incrementSize)
  1000. >  {
  1001. >    OSErr retCode;
  1002. >  
  1003. >    // increase the stack size by lowering the heap limit
  1004. >    SetApplLimit((Ptr) ((unsigned long) GetApplLimit() - incrementSize));
  1005. >    retCode = MemError();
  1006. >    if (retCode == noErr) MaxApplZone();
  1007. >  
  1008. >    return retCode;
  1009. >  }
  1010. >
  1011. >Do heed the warning given in the comment.  All stack allocation beyond
  1012. >the default must be compensated for by increasing the partition size in
  1013. >the SIZE -1 resource.  
  1014. >
  1015.  
  1016. Be forwarned to test this on many machines (namely an SE or other 68000
  1017. based machine).  I believe I tried this; it may have even been one of 
  1018. my first attempts.  I think this works but is it what is desired?
  1019.  
  1020. This increases the stack size by an amount.  It does not _SET_ the stack
  1021. size.  I needed (as I believe the original author did) to set the 
  1022. stack size to a particular size.
  1023.  
  1024. ...Duane
  1025.  
  1026. +++++++++++++++++++++++++++
  1027.  
  1028. From: grobbins@Apple.COM (Grobbins)
  1029. Date: 4 Sep 92 03:25:10 GMT
  1030. Organization: Apple Computer Inc., Cupertino, CA
  1031.  
  1032. In article <1992Sep3.180837.8540@novell.com> damurphy@wc.novell.com (Duane A Murphy) writes:
  1033. >This increases the stack size by an amount.  It does not _SET_ the stack
  1034. >size.  I needed (as I believe the original author did) to set the 
  1035. >stack size to a particular size.
  1036.  
  1037. The original poster wanted to be guaranteed at least a 32K stack 
  1038. regardless of the application's partition size setting.
  1039.  
  1040. It is not a good idea to set the stack to a specific size (although it
  1041. can be done by setting ApplLimit to CurStackBase minus the desired size)
  1042. because the System may decide to make demands of your stack beyond
  1043. the normal default.  It can do so safely by just upping the default
  1044. stack and partition sizes when launching.
  1045.  
  1046. This happened with the introduction of Color QuickDraw.  Additional
  1047. stack space was necessary for safe QuickDraw use, so the default stack
  1048. size was upped to 24K and the partition size of each application was
  1049. increased upon launch to accomodate the larger stack.
  1050.  
  1051. Any application which sets a specific stack size after launching
  1052. defeats the ability of System software to increase the stack.
  1053. At the time the program is written, 16K may be plenty large for the
  1054. stack, but that may not be true for the same program under some
  1055. future version of System software.
  1056.  
  1057. For this reason, DTS has for some time advocated that the stack be 
  1058. increased when necessary (by lowering ApplLimit), but not fixed to 
  1059. a specific size.
  1060.  
  1061. Grobbins           grobbins@apple.com
  1062.  
  1063. Usual disclaimers apply.
  1064.  
  1065.  
  1066. +++++++++++++++++++++++++++
  1067.  
  1068. From: phils@chaos.cs.brandeis.edu (Phil Shapiro)
  1069. Date: 4 Sep 92 14:03:50 GMT
  1070. Organization: Symantec Corp.
  1071.  
  1072. >>>>> On Wed, 2 Sep 92 20:23:29 GMT, buckeye@spf.trw.com (John Wallace) said:
  1073.  
  1074.  > if (StackSpace() < STACK_MIN)
  1075.  >     SetApplLimit(StackPtr() - (STACK_MIN - StackSpace()))
  1076.  
  1077.  > This will make sure that you don't waste too much memory on "Large"
  1078.  > machines.  (StackSpace is a standard Toolbox trap.)
  1079.  
  1080. This is the best solution, but... On 68000 machines, the trap
  1081. StackSpace() returns garbage unless you've already called
  1082. MaxApplZone() (in which case the call to SetApplLimit will fail). I'm
  1083. not sure, but this may have been fixed in System 7.
  1084.  
  1085. In any event, I would recommend using the low memory global DefltStack
  1086. instead. In THINK C, you can just write:
  1087.  
  1088.     SetApplLimit(GetApplLimit() - (STACK_NEEDED - DefltStack));
  1089.  
  1090. In MPW C, you'd use:
  1091.  
  1092.     SetApplLimit(GetApplLimit() - (STACK_NEEDED - *((long *)DefltStack)));
  1093.  
  1094. In Pascal, you'd use:
  1095.  
  1096.     SetApplLimit(GetApplLimit - (STACK_NEEDED - LongPtr(DefltStack)^));
  1097.  
  1098. Is this in the FAQ?
  1099.  
  1100.     -phil
  1101. - --
  1102.    Phil Shapiro                                   Software Engineer
  1103.    Language Products Group                     Symantec Corporation
  1104.            Internet: phils@cs.brandeis.edu
  1105.  
  1106. +++++++++++++++++++++++++++
  1107.  
  1108. From: damurphy@wc.novell.com (Duane A Murphy)
  1109. Date: 4 Sep 92 16:00:59 GMT
  1110. Organization: Novell, Inc. - Walnut Creek
  1111.  
  1112. In article <PHILS.92Sep4090350@chaos.cs.brandeis.edu> phils@chaos.cs.brandeis.edu (Phil Shapiro) writes:
  1113. >>>>>> On Wed, 2 Sep 92 20:23:29 GMT, buckeye@spf.trw.com (John Wallace) said:
  1114. >
  1115. > > if (StackSpace() < STACK_MIN)
  1116. > >     SetApplLimit(StackPtr() - (STACK_MIN - StackSpace()))
  1117. >
  1118. > > This will make sure that you don't waste too much memory on "Large"
  1119. > > machines.  (StackSpace is a standard Toolbox trap.)
  1120. >
  1121. >This is the best solution, but... On 68000 machines, the trap
  1122. >StackSpace() returns garbage unless you've already called
  1123. >MaxApplZone() (in which case the call to SetApplLimit will fail). I'm
  1124. >not sure, but this may have been fixed in System 7.
  1125. >
  1126. >In any event, I would recommend using the low memory global DefltStack
  1127. >instead. In THINK C, you can just write:
  1128. >
  1129. >    SetApplLimit(GetApplLimit() - (STACK_NEEDED - DefltStack));
  1130. ...
  1131.  
  1132. Thank you for jogging my memory.  This is the problem that I ran into.
  1133. Once MaxApplZone is called adjusting the stack space larger will
  1134. cross into the heap space simulating a stack heap collision.  That is
  1135. why it was necassary to adjust the stack size at the start as opposed
  1136. to dynamically at run time. (I think this sounds rights).
  1137.  
  1138. How can one adjust the stack size dynamically (as recommended by DTS)
  1139. when it simulates moving the stack into the heap?
  1140.  
  1141. No it is not fixed on System 7.  In fact StackSpace() works differently on
  1142. different models with the _SAME_ system!  This was very confusing.
  1143.  
  1144. ...Duane
  1145.  
  1146. +++++++++++++++++++++++++++
  1147.  
  1148. From: ksand@apple.com (Kent Sandvik)
  1149. Date: 5 Sep 92 21:03:26 GMT
  1150. Organization: Apple
  1151.  
  1152. In article <marshall-020992143552@hpsdr160.sdd.hp.com>, marshall@sdd.hp.com
  1153. (Marshall Clow) wrote:
  1154. > In article <71922@apple.Apple.COM>, grobbins@Apple.COM (Grobbins) wrote:
  1155. > > [ lots of good advice deleted ]
  1156. > > 
  1157. > > This is particularly an issue for faceless background apps, which have
  1158. > > a default stack size of only 2K.  SetApplLimit will grow an FBA's stack
  1159. > > to at least 24K on Color QuickDraw machines, so the partition size
  1160. > > should be larger than that.
  1161. > > 
  1162. > In writing a FBA we tracked down several cases where inits (oops,
  1163. > extensions) would patch a trap, and then when the trap was called, would
  1164. > casually throw a few Str255s on the stack, or maybe a 1K buffer.
  1165. > Needless to say, when an OS call used over 1K of stack space and you only
  1166. > have a 2K stack, you are headed for problems.
  1167.  
  1168. Another hint, check out what MoveHHi is doing with the stack. I'm not 
  1169. telling it :-).
  1170.  
  1171. Kent Sandvik/DTS
  1172.  
  1173. +++++++++++++++++++++++++++
  1174.  
  1175. From: chuckp@u.washington.edu (Chuck Pliske)
  1176. Date: 9 Sep 92 05:24:09 GMT
  1177. Organization: University of Washington
  1178.  
  1179. In article <1992Sep4.160059.29329@novell.com> Duane A Murphy,
  1180. damurphy@wc.novell.com writes:
  1181. >>In any event, I would recommend using the low memory global DefltStack
  1182.  
  1183. I wrote an extension "Stack6000", useful for the 68000 machines because
  1184. Apple sets the default stack to about $4800 in the Plus, SE and PB100,
  1185. and $6000 on the other machines.  I simply set DefltStack to $6000 (if
  1186. needed) and exit.  Subsequent programs using the default all get the new
  1187. value.  So far, it has worked fine.  (Available on Sumex)
  1188.  
  1189. Chuck
  1190.  
  1191. ---------------------------
  1192.  
  1193. End of C.S.M.P. Digest
  1194. **********************
  1195.